<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="添加文本" onclick="f(1)">
<input type="button" value="添加图片" onclick="f(2)">
<script>
    let i = document.querySelector("input");
    function f(x){
       switch (x){
           case 1:
               let h = document.createElement("h1")
               h.innerText=i.value;
               document.body.append(h);
               break
           case 2:
               let img = document.createElement("img");
               img.src="b.png";
               document.body.append(img);
               break
       }
    }
    fo
</script>
</body>
</html>